from lxml import etree

if __name__ == "__main__":
    tree = etree.parse("./file/test.html")
    # r = tree.xpath("/html/body/div")
    # 多层级
    # r = tree.xpath("/html//div")
    # r = tree.xpath("//div")
    # r = tree.xpath("//div[@class='song']")
    # 索引从1开始
    # r = tree.xpath('//div[@class="tang"]//li[5]/a/text()')[0]
    # 直系文本内容
    # r = tree.xpath('//li[7]/text()')
    # 多层级文本内容
    # r = tree.xpath('//li[7]//text()')
    # r = tree.xpath('//div[@class="tang"]//text()')
    r = tree.xpath('//div[@class="song"]/img/@src')

    print(r)
